<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

/**
 * 后台配置控制器
 * @author yangweijie <yangweijiester@gmail.com>
 */
class OrderController extends AdminController {


    public function order(){
        $param = $_GET;

        // 返回字段
        $field = 'id,user_id,good_info,amount,create_time,order_no';

        // 构造查询条件
        $where = array();

        if($param['status']){
            $where['status'] = $param['status'];
        }
        $param['type']?$where['type']=$param['type']:"";
        $option['page'] = I('data.page', '', '/^\d+$/', $param) ? $param['page'] : 1;
        $option['size'] = I('data.size', '', '/^\d+$/', $param) ? $param['size'] :30;

        $list = D('Invest')->searchInvest($where, $option, 'create_time desc', $field);
        $returninfo = array();
        foreach($list as $key=>$val){
            if($val['status'] == '3'){
                $val['controller'] = '<a class="open-html open-express"  code="'.$val['id'].'">发货</a><br>';
            }
            if($val['status'] == '1'){
                $val['controller'] = '<a class="open-html open-delivery" href="admin.php?s=/Order/checkevaluated/id/'.$val['id'].'.html" >查看评价</a><br>';
            }
            if($val['status'] == '2'){
                $val['controller'] = '<a class="cacelorder" code="'.$val['id'].'">取消</a><br>';
            }
            $returninfo[$key] = $val;
        }

//									<a class="open-html open-checkshipped" href="http://localhost/qgh/admin.php?s=/Order/checkshipped.html">物流信息</a><br>
//									<a class="open-html open-checkshipped" href="http://localhost/qgh/admin.php?s=/Order/checkevaluated.html">查看评价</a><br>
        $this->assign("_list",$returninfo);
        $this->display();
    }
    public function changeexpress(){
        $id = $_POST['id'];
        $express_code = $_POST['express_code'];
        $express_type = $_POST['express_type'];
        M("Invest")->where(array("id"=>$id))->save(array("status"=>'4'));
        M("Express")->add(array("express_code"=>$express_code,"type"=>$express_type,"invest_id"=>$id));
    }
    //取消订单
    public function cancelorder(){
        $id = $_POST['id'];
        M("Invest")->where(array("id"=>$id))->save(array("status"=>'10'));
    }
    //评论列表
    public function checkevaluated(){
        $id = $_GET['id'];
        $commentinfo =  M("Comment")
            ->join("left join mt_good on mt_comment.good_id=mt_good.id")->where(array("mt_comment.invest_id"=>$id))->select();

        $this->assign("_list",$commentinfo);
        $this->display();
    }
}
